package com.boot2.core.conf;

import com.boot2.core.SysProperties;
import com.boot2.core.constant.CoreUrlConstant;
import com.boot2.core.utils.FileUtil;
import lombok.Data;
import lombok.SneakyThrows;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.File;

/**
 * @author zhangweilin
 * @date 2020/5/25 19:08
 * @Description:
 */
@Data
@Configuration
//@ConfigurationProperties(prefix = "sys.core.tmp")
@Component
@CommonsLog
public class SysTmpConf {

    @Autowired
    SysProperties sysProperties;

    @SneakyThrows
    @PostConstruct
    public void init() {
        String path = sysProperties.getTmpPath();
        File file = new File(path);
        if (!file.exists()) {
            log.info("系统临时目录【" + path + "】(可以通过sys.tmp-path配置指定)不存在，系统将自动创建");
            FileUtil.createDir(path);
//            file.createNewFile();
        }
        CoreUrlConstant.tmpPath = path;
        log.info("系统将采用临时目录【" + path + "】(可以通过sys.tmp-path配置指定)");
    }
}
